<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/24-16:17
 * Link: https://gitee.com/luckygyl/LuckyAdmin
 * FileName: index.html
 *-->
<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/24-15:02
 * Link: https://gitee.com/luckygyl/LuckyAdmin
 * FileName: index.html
 *-->

{include file="public/head" /}

<body>
<!-- 正文开始 -->
<div class="layui-fluid">

    <div class="layui-row layui-col-space10">

        <div class="layui-col-md12">

            <?php echo Form::Search('name','用户名称','支持模糊搜索');?>


            <!--右侧表格开始-->
            <div class="layui-card">
                <div class="layui-card-header" style="line-height: 55px;">
                    <div class="layui-btn-container do_btn">
                        <button class="layui-btn layui-btn-sm layui-btn-danger"  data-type="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary"  data-type="reload"> <i class="fa fa-refresh"></i> 刷新</button>
                    </div>
                </div>
                <div class="layui-card-body">

                    <div class="yys-fluid yys-wrapper">
                        <div class="layui-row lay-col-space20">
                            <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                                <section class="yys-body">
                                    <div class="yys-body-content clearfix changepwd">
                                        <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                            <div class="user-tables">
                                                <table id="tableFilter" lay-filter="tableFilter"> </table>
                                            </div>
                                        </div>
                                    </div>
                                </section>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <!--右侧表格结束-->

        </div>

    </div>


</div>

<style type="text/css">
    .layui-table-cell{
        text-align:center;
        height: auto;
        white-space: normal;
    }
    .layui-table img{
        max-width:300px;
        max-height: 50px;
    }
</style>

<!--模板-->
<script type="text/html" id="operationTpl">
    <a href="javascript:;"   class="layui-btn layui-btn-normal layui-btn-xs "  onmouseover="tis(this)"  data-title="编辑用户信息" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a href="javascript:;"   class="layui-btn layui-btn-danger layui-btn-xs "  onmouseover="tis(this)"  data-title="删除会员" lay-event="del"><i class="layui-icon " >&#xe640;</i></a>
</script>


<script type="text/html" id="status">
    <input type="checkbox" name="status"  lay-data="{{d.status}}" value="{{d.id}}"  lay-filter="sexDemo" lay-skin="switch"  lay-text="正常|拉黑"  {{ d.status == 1 ? 'checked' : '' }}>
</script>


{include file="public/js" /}


<script>

    layui.use(['element', 'table', 'form', 'jquery', 'laydate','util'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        var util=layui.util;

        form.render();


        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('users/index')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:20
                ,limits:[20,30,40,50,60,100]
            },
            // height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                // {field: 'id',  title: 'ID',width:60},
                {field: 'image',style:'cursor: pointer;', width: 120, align: 'center',title: '头像',templet:function (d) {
                        return '<img  src="'+d.image+'"  alt="头像" class="layui-nav-img" />';
                    }},
                {field: 'qq', width: 150, style:'cursor: pointer;', align: 'center',title: 'qq号码',templet:function (d) {
                        return '<a href="tencent://message/?uin='+d.qq+'&amp;Site=&amp;Menu=yes" target="_blank" title="点击联系他" >'+d.qq+'</a>';
                    }},
                {field: 'username',align: 'center', minWidth: 170, title: 'QQ昵称'},
                {field: 'zan', width: 120, title: '点赞数',align: 'center',sort:true},
                {field: 'fen', width: 120, title: '积分数',align: 'center',sort:true},
                {field:'status',title:'状态',align: 'center',templet: '#status',width:120 ,sort:true,unresize: true},
                {field: 'ip', width: 150,align: 'center', title: 'IP'},
                {field: 'time_formt', title: '添加时间',align: 'center',width:180},
                {fixed: 'right',templet: '#operationTpl', width: 100, align: 'center', title: '操作'}
            ]],

            done: function (res) {
                layer.closeAll('loading');
                hoverOpenImg();
            }
        });


        function hoverOpenImg(){
            var img_show = null; // tips提示
            $('td img').hover(function(){
                var img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:100%;max-height: 600px;' />";
                img_show = layer.tips(img, this,{
                    tips:[2, 'rgba(41,41,41,.0)']
                    ,area: ['12%']
                });
            },function(){
                layer.close(img_show);
            });
        }


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            CreateSearch("table_id",obj.field); //查询
            return false;
        });

        /**
         * 监听是否显示操作
         */
        form.on('switch(sexDemo)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=2;
            }else {
                status=1;
            }
            change_status("table_id","users",_id,"status",status, obj.othis);
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="edit"){
                var urls="/index.php/admin/users/EditUsers/id/"+_id;
                CreateForm("编辑会员信息",'40%','50%',urls,"table_id");

            }else if(layEvent==="del"){
                delete_data(_id,"{:url('users/delete')}","table_id",'确定删除选这个会员吗？');
            }

        });


        var active = {
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                delete_data(id,"{:url('users/delete')}","table_id",'确定删除选中的会员信息吗？');
            },
            reload: function(){
                CreateReload("table_id");
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


</body >
</html >